找传奇、传世资源到传世资源站!

ComboBox 绑定List ArrayList 数据源示例源码

8.5玩家评分(1人评分)
下载后可评
介绍 评论 失效链接反馈

msdn说: DisplayMember is set to the comboBox control, it uses the default ToString of the object,
public class Person{ public int Id { get; set; } public string Name { get; set; } public string Lastname { get; set; } public override string ToString() { return String.Format("{0} {1}", Name, Lastname); }}private void button2_Click(object sender, EventArgs e){ var people = LoadSamplePeople();//.DisplayMember is set to the comboBox control, it uses the default ToString of the object,comboBox1.ValueMember = "Id"; comboBox1.DataSource = people;}private IEnumerable<Person> LoadSamplePeople(){ return new List<Person>() { new Person(){ Id = 1, Name = "Sergio", Lastname = "Tapia" }, new Person(){ Id = 2, Name = "Daniel", Lastname = "Tapia" } };}

评论

发表评论必须先登陆, 您可以 登陆 或者 注册新账号 !


在线咨询: 问题反馈
客服QQ:174666394

有问题请留言,看到后及时答复